/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class ToeplitzMatrix {
	public boolean isToeplitzMatrix(int[][] matrix) {
		int n = matrix.length;
		int m = matrix[0].length;
		for (int i = 0; i < m; i++) {// 第一行为起始
			int val = matrix[0][i];
			int startI = 1, startJ = i + 1;
			while (startI < n && startJ < m) {
				if (matrix[startI][startJ] != val) {
					return false;
				}
				startI++;
				startJ++;
			}
		}
		for (int i = 1; i < n; i++) {
			int val = matrix[i][0];
			int startI = i + 1, startJ = 1;
			while (startI < n && startJ < m) {
				if (matrix[startI][startJ] != val) {
					return false;
				}
				startI++;
				startJ++;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		int[][] matrix = { { 1, 2 }, { 2, 2 } };// { { 1, 2, 3, 4 }, { 5, 1, 2, 3 }, { 9, 5, 1, 2 } };
		System.out.println(new ToeplitzMatrix().isToeplitzMatrix(matrix));
	}
}
